package com.waves.message.strategy;


import cn.hutool.extra.spring.SpringUtil;
import com.waves.core.constant.MQConstant;
import com.waves.core.transaction.MultiplyThreadTransactionManager;
import com.waves.message.domain.dto.PushMessageDTO;
import com.waves.message.domain.entity.MessageRecord;
import com.waves.message.domain.vo.WSBaseVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * 系统内部通知策略
 * @author Eden
 * @date 2025/01/01 16:49
 **/
@Component
@Slf4j
public class SystemInsideStrategy implements AbstractINoticeStrategy {

    private static RabbitTemplate rabbitTemplate;

    static {
        rabbitTemplate = SpringUtil.getBean(RabbitTemplate.class);
    }

    @Override
    public void sendMessage(MessageRecord messageRecord) {
        List<Long> uidList = Collections.singletonList(messageRecord.getReceiveUserId());
        WSBaseVO<Object> vo = new WSBaseVO<>();
        vo.setType(12);
        vo.setData(messageRecord.getMessageContext());
        // 消息中心发送给websocket进行通知
        rabbitTemplate.convertAndSend(MQConstant.ORDER_EVENT_EXCHANGE, MQConstant.WEBSOCKET_PUSH_MSG,
                new PushMessageDTO(uidList, vo));
        log.info("给webSocket发送一条mq消息");
    }
}
